package org.example.service;

import org.example.bean.User;
import org.example.mapper.UserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class UserServiceImpl implements IUserService {

    private final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private UserMapper userMapper;


    @Override
    public User queryUser(int id) {
        logger.info("The user id is " + id);
        return userMapper.selectByPrimaryKey(id);
//        return null;
    }

    @Transactional
    @Override
    public int addUser(User user) {
        logger.info("The user to add is " + user);
        return userMapper.insert(user);
//        return 0;
    }

    @Transactional
    @Override
    public int deleteUser(int id) {
        logger.info("The user id is " + id);
        return userMapper.deleteByPrimaryKey(id);
//        return 0;
    }
}
